﻿using System.Windows.Forms;

namespace RegexSharp.Control
{
    public class RSTextBox : TextBox
    {
        public RSTextBox()
        { }

        // Public Methods

        private delegate void SetTextCallBack(string text, params object[] args);
        public void SetText(string text, params object[] args)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new SetTextCallBack(SetText), new object[] { text, args });
            }
            else
            {
                if (args.Length > 0)
                {
                    this.Text = string.Format(text, args);
                }
                else
                {
                    this.Text = text;
                }
            }
        }

        private delegate void SetAppendTextCallBack(string text, params object[] args);
        public void SetAppendText(string text, params object[] args)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new SetAppendTextCallBack(SetAppendText), new object[] { text, args });
            }
            else
            {
                if (args.Length > 0)
                {
                    this.AppendText(string.Format(text, args));
                }
                else
                {
                    this.AppendText(text);
                }
            }
        }
    }
}
